﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace TJ_MainNameSpace
{
    public partial class DrawSetting : Form
    {
        public DrawSetting()
        {
            InitializeComponent();
        }
        public static string[] CurveName = null;
        public static Color[] CurveColor = null;
        public static float[] CurveWidth = null;
        public static string Title = "";
        public static string XText = "";
        public static string YText = "";
        public DrawSetting(string[] PointName, CurveOption CO)
        {
            InitializeComponent();
            switch (CO)
            {
                case CurveOption.ByCustom:
                    if (PointName != null)
                    {
                        dataGridView1.Rows.Add(PointName.Length);
                        for (int i = 0; i < PointName.Length; i++)
                        {
                            dataGridView1[0, i].Value = PointName[i];
                            dataGridView1[1, i].Value = PointName[i];
                            dataGridView1[2, i].Style.BackColor = Color.White;
                            dataGridView1[3, i].Value = "1";
                        }
                    }
                    break;
                case CurveOption.ByDay:
                    if (PointName != null)
                    {
                        dataGridView1.Rows.Add(PointName.Length);
                        for (int i = 0; i < PointName.Length; i++)
                        {
                            dataGridView1[0, i].Value = PointName[i];
                            dataGridView1[1, i].Value = PointName[i];
                            dataGridView1[2, i].Style.BackColor = Color.White;
                            dataGridView1[3, i].Value = "1";
                        }
                    }
                    break;
                case CurveOption.ByMonth:
                    if (PointName != null)
                    {
                        for (int i = 0; i < PointName.Length; i++)
                        {
                            dataGridView1.Rows.Add(3);
                            dataGridView1[0, i * 3].Value = PointName[i] + "月最大值";
                            dataGridView1[1, i * 3].Value = PointName[i] + "月最大值";
                            dataGridView1[2, i * 3].Style.BackColor = Color.Red;
                            dataGridView1[3, i * 3].Value = "1";
                            dataGridView1[0, i * 3 + 1].Value = PointName[i] + "月平均值";
                            dataGridView1[1, i * 3 + 1].Value = PointName[i] + "月平均值";
                            dataGridView1[2, i * 3 + 1].Style.BackColor = Color.White;
                            dataGridView1[3, i * 3 + 1].Value = "1";
                            dataGridView1[0, i * 3 + 2].Value = PointName[i] + "月最小值";
                            dataGridView1[1, i * 3 + 2].Value = PointName[i] + "月最小值";
                            dataGridView1[2, i * 3 + 2].Style.BackColor = Color.Green;
                            dataGridView1[3, i * 3 + 2].Value = "1";
                        }
                    }
                    break;
                case CurveOption.ByYear:
                    if (PointName != null)
                    {
                        for (int i = 0; i < PointName.Length; i++)
                        {
                            dataGridView1.Rows.Add(3);
                            dataGridView1[0, i * 3].Value = PointName[i] + "年最大值";
                            dataGridView1[1, i * 3].Value = PointName[i] + "年最大值";
                            dataGridView1[2, i * 3].Style.BackColor = Color.Red;
                            dataGridView1[3, i * 3].Value = "1";
                            dataGridView1[0, i * 3 + 1].Value = PointName[i] + "年平均值";
                            dataGridView1[1, i * 3 + 1].Value = PointName[i] + "年平均值";
                            dataGridView1[2, i * 3 + 1].Style.BackColor = Color.White;
                            dataGridView1[3, i * 3 + 1].Value = "1";
                            dataGridView1[0, i * 3 + 2].Value = PointName[i] + "年最小值";
                            dataGridView1[1, i * 3 + 2].Value = PointName[i] + "年最小值";
                            dataGridView1[2, i * 3 + 2].Style.BackColor = Color.Green;
                            dataGridView1[3, i * 3 + 2].Value = "1";
                        }
                    }
                    break;
                default:
                    break;
            }

        }


        private void button7_Click(object sender, EventArgs e)//字体对话框
        {
            if (this.fontDialog1.ShowDialog() == DialogResult.OK)
            {
                Font font = this.fontDialog1.Font;
            }
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 2)
            {
                if (this.colorDialog1.ShowDialog() == DialogResult.OK)
                {
                    Color color = this.colorDialog1.Color;
                    DataGridViewCellStyle st = new DataGridViewCellStyle();
                    st.BackColor = color;
                    dataGridView1[2, e.RowIndex].Style = st;
                }
            }
        }

        private void OK_Click(object sender, EventArgs e)
        {
            if (dataGridView1.Rows.Count > 1)
            {
                CurveName = new string[dataGridView1.Rows.Count - 1];
                CurveColor = new Color[dataGridView1.Rows.Count - 1];
                CurveWidth = new float[dataGridView1.Rows.Count - 1];
            }
            for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            {
                if (dataGridView1[0, i].Value == null)
                {
                    MessageBox.Show("请填写完整！");
                    return;
                }
                CurveName[i] = dataGridView1[0, i].Value.ToString();
                CurveColor[i] = dataGridView1[2, i].Style.BackColor;
                CurveWidth[i] = Convert.ToSingle(dataGridView1[3, i].Value);
            }
            Title = textBox1.Text;
            XText = textBox2.Text;
            YText = textBox3.Text;
            DialogResult = DialogResult.OK;
        }

        private void Cancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }


    }
}